package com.csun.nusing.presenter;

import android.app.Activity;
import android.content.Context;

import com.csun.nusing.bean.UrlBean;
import com.csun.nusing.bean.jsonbean.BaseJsonBean;
import com.csun.nusing.presenter.inter.IBase;
import com.csun.nusing.util.SPUtils;
import com.csun.nusing.util.ToastUtil;
import com.google.gson.Gson;
import com.home.administrator.okhttplibrary.IOkTaskCallback;
import com.home.administrator.okhttplibrary.OkHttpTask;
import com.home.administrator.okhttplibrary.OkHttpTask.OkHttpTaskBuidler.OkType;

import java.util.HashMap;

/**
 * 报警反馈接面的p层
 * ClassName: NursingAlarmAnswerPresenter 
 * @Description: TODO
 * @author fzq
 * @date 2017-10-28
 */
public class NursingAlarmAnswerPresenter extends BasePresenter<IBase> {

	private String authorization;

	public NursingAlarmAnswerPresenter(IBase view) {
		super(view);
	}

	/**
	 * 提交反馈
	 */
	public void enter(final Context context,String id,String result,String evaluate,String resultText){
		authorization = (String) SPUtils.get(context, "authorization", "");
		HashMap<String, String> param = new HashMap<String,String>();
		param.put("id", id);
		param.put("result", result);
		param.put("evaluate", evaluate);
		param.put("resultText", resultText);
		OkHttpTask.newInstance(context).addHeader("authorization", authorization).post(param, OkType.form).enqueue(new IOkTaskCallback() {
			@Override
			public void onSuccess(String result) {
				Gson gson = new Gson();
				if (result!=null) {
					BaseJsonBean bean = gson.fromJson(result, BaseJsonBean.class);
					if (bean!=null) {
						ToastUtil.showMessage(context, bean.getMessage());
						((Activity) context).finish();
					}
				}
			}
		}).start(UrlBean.ALERTFEEDBACKURL);
	}
	
	
}